﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/*
    应用举例：电灯有两个状态，开（亮）与关（不亮），就用状态模式来实现对电灯的控制。
 */
namespace State
{
    public class Light
    {
        private LightState lightState;

        public LightState CurLightState
        {
            get { return lightState; }
            set { lightState = value; }
        }

        public Light(LightState state)
        {
            this.lightState = state;
        }

        //按下开关
        public void PressSwitch()
        {
            this.lightState.SwitchState(this);
        }


    }

    public abstract class LightState
    {
        public abstract void SwitchState(Light light);
    }

    public class On : LightState
    {
        public override void SwitchState(Light light)
        {
            Console.WriteLine("电灯电灯泡关闭。");
            light.CurLightState = new Off();
        }
    }

    public class Off : LightState
    {
        public override void SwitchState(Light light)
        {
            Console.WriteLine("电灯灯泡打开");
            light.CurLightState = new On();
        }
    }
}
